package GUI.Cliente;

import java.rmi.RemoteException;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import service.article.exceptions.ProxyException;

public class MainCliente extends Dialog {

	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public MainCliente(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(450, 300);
		shell.setText(getText());
		
		Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AddClient a = new AddClient (shell,  shell.getStyle());
				shell.setVisible(false);
				a.open();
			}
		});
		button.setText("Agregar Cliente");
		button.setBounds(107, 59, 236, 28);
		
		Label label = new Label(shell, SWT.NONE);
		label.setText("Eliga La Opcion Deseada");
		label.setAlignment(SWT.CENTER);
		label.setBounds(117, 27, 216, 14);
		
		Button button_1 = new Button(shell, SWT.NONE);
		button_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				VerClientesLista a = new VerClientesLista (shell, shell.getStyle());
				shell.setVisible(false);
				try {
					a.open();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ProxyException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button_1.setText("Ver Listado De Clientes");
		button_1.setBounds(107, 93, 236, 28);
		
		Button button_2 = new Button(shell, SWT.NONE);
		button_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),0);
				b.open();
			}
		});
		button_2.setText("Buscar Cliente en la Base de Datos");
		button_2.setBounds(107, 127, 236, 28);
		
		Button button_3 = new Button(shell, SWT.NONE);
		button_3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),1);
				b.open();
			}
		});
		button_3.setText("Modificar Informacion de un Cliente");
		button_3.setBounds(107, 172, 236, 28);
		
		Button button_4 = new Button(shell, SWT.NONE);
		button_4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),2);
				b.open();
			}
		});
		button_4.setText("Eliminar Cliente de la Base de Datos");
		button_4.setBounds(107, 206, 236, 28);

	}

}
